﻿using A5.TaskSer.Services.Implements;
using Base.Core20.Enums;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Winservice.demo.Models.Entities;
using Winservice.demo.Queue;


namespace Winservice.demo.Business
{
    public class TaskApproval_Business
    {
        private TaskApproval_Service ser = new TaskApproval_Service();

        /// <summary>
        /// 修改 任务审批 状态
        /// </summary>
        /// <param name="taskApprovalID"></param>
        /// <param name="taskStatusEnum"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public async Task<int> UpdateTaskApprovalStatusAsync(long taskApprovalID, FLOW_TASK_STATUS_Enum taskStatusEnum, string notes)
        {
            return await ser.UpdateTaskApprovalStatusAsync(taskApprovalID, taskStatusEnum, notes);
        }

        /// <summary>
        /// 查询 任务审批 信息（查询前20条） TASK_STATUS=102
        /// </summary>
        /// <returns></returns>
        public async Task<IEnumerable<QueueTask>> GetTaskApproval()
        {
            return await ser.GetTaskApproval();
        }

        /// <summary>
        /// 根据 IncidentID 及 SignKey 判断 会签节点 是否 已经办结了 
        /// </summary>
        /// <param name="queueTask"></param>
        /// <returns></returns>
        public async Task<SignFinished> GetSignFinished(QueueTask queueTask)
        {
            return await ser.GetSignFinished(queueTask);
        }

        /// <summary>
        /// 设置 会签节点已经结束 后的 操作
        /// 1. 把 IncidentID 及 SIGN_KEY 插入 FLOW_COUNTERSIGN_FINISHED
        /// 2. 再 根据 IncidentID 及 SIGN_KEY 把 FLOW_TASK_APPROVAL 中的 IS_CURRENT_SIGN_PATCH 修改 成 1
        /// </summary>
        /// <param name="queueTask"></param>
        /// <returns></returns>
        public async Task<int> UpdateSignStepIsFinishedAsync(QueueTask queueTask)
        {
            return await ser.UpdateSignStepIsFinishedAsync(queueTask);
        }

        /// <summary>
        /// 获得实例号 并 修改 FLOW_INCIDENT
        /// </summary>
        /// <param name="incidentID"></param>
        /// <param name="incident"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public async Task<int> UpdateIncidentNoAsync(long incidentID, string incident, string notes)
        {
            return await ser.UpdateIncidentNoAsync(incidentID, incident, notes);
        }

        /// <summary>
        /// 修改 Flow_Incident 状态 = End
        /// </summary>
        /// <param name="incidentID"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public async Task<int> UpdateIncidentStatusIsEndAsync(long incidentID, string notes)
        {
            return await ser.UpdateIncidentStatusIsEndAsync(incidentID, notes);
        }

        /// <summary>
        /// 设置 异常状态
        /// 1. 根据 IncidentID FLOW_INCIDENT PROCESS_STATUS = 1099
        /// 2. 根据 TaskApprovalID FLOW_TASK_APPROVAL TASK_STATUS = 1099
        /// </summary>
        /// <param name="incidentID"></param>
        /// <param name="taskApprovalID"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public async Task<int> UpdateStatusIsExceptionAsync(long incidentID, long taskApprovalID, string notes)
        {
            return await ser.UpdateStatusIsExceptionAsync(incidentID, taskApprovalID, notes);
        }

        /// <summary>
        /// 查询已经完成的流程信息
        /// </summary>
        /// <returns></returns>
        public async Task<IEnumerable<FLOW_INCIDENT_FINISHED>> GetFinishedIncidentByA5Async()
        {
            return await ser.GetFinishedIncidentByA5Async();
        }

        /// <summary>
        /// 设置 自定义 流程
        /// </summary>
        /// <param name="processName">流程名称</param>
        /// <param name="incident">流程实例</param>
        /// <param name="sql">sql</param>
        /// <returns></returns>
        public async Task<int> SetCustomProcess(string processName, string incident, string sql)
        {
            return await ser.SetCustomProcess(processName, incident, sql);
        }

        /// <summary>
        /// 设置 流程 已经结束
        /// </summary>
        /// <param name="processName">流程名称</param>
        /// <param name="incident">流程实例</param>
        /// <returns></returns>
        public async Task<int> SetIncidentIsEnd(string processName, string incident)
        {
            return await ser.SetIncidentIsEnd(processName, incident);
        }

        /// <summary>
        /// 设置 流程 已经中止
        /// </summary>
        /// <param name="processName">流程名称</param>
        /// <param name="incident">流程实例</param>
        /// <returns></returns>
        public async Task<int> SetIncidentIsAbort(string processName, string incident)
        {
            return await ser.SetIncidentIsAbort(processName, incident);
        }

        /// <summary>
        /// 查询 180 天前的所有 已经 办结或者撤销的流程（103,104）
        /// </summary>
        /// <param name="daysByDelete"></param>
        /// <returns></returns>
        public async Task<IEnumerable<FLOW_INCIDENT_DELETE>> GetDeleteIncidentIDAsync(string daysByDelete)
        {
            return await ser.GetDeleteIncidentIDAsync(daysByDelete);
        }

        /// <summary>
        /// 根据 实例ID 转移 或 删除 相关业务表信息
        /// </summary>
        /// <param name="incidentID"></param>
        /// <returns></returns>
        public async Task<int> DeleteInfoByIncidentID(long incidentID)
        {
            return await ser.DeleteInfoByIncidentID(incidentID);
        }

        /// <summary>
        /// 增加 终止 流程 记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> LogAbortRecordAsync(LOG_ABORTED model)
        {
            return await ser.LogAbortRecordAsync(model);
        }





    }
}
